<?php
    /**
     * Created by PhpStorm.
     * User: zgh
     * Date: 2021-08-06
     * Time: 11:23
     */

    namespace app\api\service;


    use app\common\model\AdvModel;

    class AdvService
    {
        public static function getList($params)
        {
            $pagination = filter_pagination(@$params['page'], @$params['limit']);
            $where = [];
            $data = [];
            if (isset($params['title']) && !empty($params['title'])) {
                $where[] = ["title", "like", "%" . $params['title'] . "%"];
            }
            if (isset($params['type']) && is_numeric($params['type'])) {
                $where[] = ["type", "=", $params['type']];
            }
            $where[] = ['status', '=', 1];
            $query = AdvModel::field("id,type,title,jump_type,jump_url,images")->where($where)->order(["weight" => "desc", "create_time" => "desc"]);
            $data['total'] = $query->count();
            $data['dataList'] = [];
            if ($data['total']) {
                $data['dataList'] = $query->limit($pagination['start'], $pagination['limit'])->select()->toArray();
                foreach ($data['dataList'] as &$data_row) {
                    $data_row['images'] = get_http_path($data_row['images']);
                }
            }
            return $data;
        }
    }